package inabit.expressioncompiler.productions;

import inabit.compiler.parser.grammar.NonTerminal;
import inabit.compiler.parser.grammar.Production;
import inabit.compiler.parser.grammar.Symbol;
import inabit.compiler.parser.grammar.Terminal;
import inabit.data.expression.arithmetic.NegativeExpression;
import inabit.expressioncompiler.lexical.ExpressionTokenClass;
import inabit.expressioncompiler.parser.ExpressionSemanticAction;

/** Z -> -Z */
/**@author Rafael Rocha*/
public class Z_Rule5 extends Production {
	private NonTerminal Z;

	public Z_Rule5() {
		super("Z");
	}

	@Override
	protected Symbol[] production(final NonTerminal nonTerminal) {
		Z = new NonTerminal("Z");

		Symbol[] symbols = { new Terminal(ExpressionTokenClass.MINUS), Z,
				new ExpressionSemanticAction(nonTerminal) {
					public void execute() {
						nonTerminal.code = addArithmeticExpressionAndGetCode(new NegativeExpression(
								getArithmeticExpression(Z.code)));
					}
				} };
		return symbols;
	}

}
